/**
 * zhanjun
 */

$(function() {

	
	var urlId="";
	var urlkey="id";
	//解析获取的url id参数
	var reg = new RegExp("(^|&)"+urlkey+"=([^&]*)(&|$)","i");
	var r = window.location.search.substr(1).match(reg);	 	   
	if (r!=null) 
	{	
		urlId=unescape(r[2]); 		
	}
	
	/*
	 * 初始加载数据
	 */
	$.getJSON("../resource/ser_load.do?id="+urlId, function(data) {
		if(data){			
			$("#resName").attr("value",data.resName);
			$("#resource").attr("value",data.resource);			
			$("#orderby").attr("value",data.orderby);
			$("#idResource").attr("value",data.idResource);
			$("#resDesc").attr("value",data.resDesc);
			
			
		}else{
			alert("数据载入出错!");
			history.go(-1);
		}

	});

	
	/*
	 * 更新事件
	 */

	$("#btn_submit").click(function() {
		var postdata = $('#dataform').serialize();
		if($('#dataform').form('validate')){	
		$.ajax({
			type : "POST",
			url : "../resource/ser_update.do",
			data : postdata,
			success : function(msg) {
				alert(msg);
				history.go(-1);
				
			}
		});
		}
	});

});
